﻿using Log.Log;
using System.Configuration;
using System.Data;
using System.Data.SQLite;


namespace FixtureManageSystem
{
    public class SqliteHelper
    {
        static SQLiteConnection conn;

        public  SQLiteConnection getConn()
        {
            if (conn == null)
            {
                conn = new SQLiteConnection(ConfigurationManager.ConnectionStrings["SqliteConnection"].ConnectionString);
            }
            if (conn.State == ConnectionState.Closed)
            {
                conn.Open(); // 打开数据库
            }
            return conn; // 返回数据库对象
        }

        public  SQLiteCommand command(string sql)
        {
            new LogFactory().GetLog("loger").Info(true, sql);
            SQLiteCommand cmd = new SQLiteCommand(sql, getConn());
            return cmd;
        }
        public int Execute(string sql) // 更新操作
        {
            return command(sql).ExecuteNonQuery();
        }
        public SQLiteDataReader read(string sql) // 读取操作
        {
            return command(sql).ExecuteReader();
        }
    }
}
